#ifndef __thr_h__
#define __thr_h__

#include <pthread.h>
/* prctl Only support in Linux */
#ifdef OS_Linux
#include <sys/prctl.h>
#endif
#include <time.h>

/* 枚举：线程运行标志 */
typedef enum __thread_flag{
    THREAD_FLAG_STOP    = 0,
    THREAD_FLAG_RUNNING = 1,
    THREAD_FLAG_NONE    = -1
}THREAD_FLAG;

typedef struct __thread_handle
{
    THREAD_FLAG     tFlag;
    pthread_t       tID;
    void*           tPara;
    void*           (*tFunction)(void* para);
#ifdef OS_Linux
    char            tName[64];
#endif
    time_t 			uptime;
    char			runtime[256];
}THR_HND;

void THREAD_SetProperty_before_infinite_loop(struct __thread_handle* thrhnd, char* thread_name);

int THREAD_Construct(struct __thread_handle* thrhnd, 
						void* (*function)(void* para), void* parameter);

void THREAD_Deconstruct(struct __thread_handle* thrhnd);

struct __thread_handle* thr_get_handle(pthread_t thr_id);
char* thr_running_time(struct __thread_handle* thrhnd);
#define thr_property(thr, name)		THREAD_SetProperty_before_infinite_loop(thr, name)
#define thr_construct(thr, fx, arg)	THREAD_Construct(thr, fx, arg)
#define thr_release(thr)			THREAD_Deconstruct(thr)

#endif
